package com.lzx.activity.controller;

import com.lzx.activity.entity.Voucher;
import com.lzx.activity.service.VoucherService;
import com.lzx.common.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lzx
 * @since 2022-11-10
 */
@RestController
@RequestMapping("/activity/voucher")
public class VoucherController {
    @Resource
    private VoucherService voucherService;

    //根据活动id获取优惠券
    @GetMapping("/getVoucherById/{activityId}")
    public R getVoucherById(@PathVariable Integer activityId) {
        return voucherService.getVoucherById(activityId);
    }

    //添加优惠券
    @PostMapping("/addVoucher")
    public R addVoucher(@RequestBody Voucher voucher) {
        return voucherService.addVoucher(voucher);
    }

    //修改优惠券
    @PutMapping("/updateVoucher")
    public R updateVoucher(@RequestBody Voucher voucher) {
        return voucherService.updateVoucher(voucher);
    }

    //上架或下架优惠券
    @PutMapping("/deleteVoucher/{id}/{status}")
    public R deleteVoucher(@PathVariable Long id, @PathVariable Integer status) {
        return voucherService.deleteVoucher(id, status);
    }

    //根据id获取优惠券信息
    @GetMapping("/{id}")
    public R getVoucher(@PathVariable Long id) {
        return voucherService.getVoucher(id);
    }
}
